<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
class Index extends Controller
{

    public function index()
    {
        header("Content-type: text/html; charset=utf-8");
        $arr=array();
        $all_arr=array();
        $paged=Request::instance()->param('page');
        //$paged=1;
    	$ch1 = curl_init();
        $url = "http://www.jdlingyu.mobi/collection/cos";
         
        $data1="paged={$paged}";
        curl_setopt($ch1, CURLOPT_URL,$url);
        curl_setopt($ch1, CURLOPT_POST, 1); 
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch1, CURLOPT_HEADER, 0); 
        curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
        $result=curl_exec($ch1); 
        curl_close($ch1);



        $pat1='/<div style="background-image:url(.*?)" class="preview thumb-in"><\/div>/';
        
        $pat3='/<h2 class="entry-title"><a target="_blank" href="(.*?)" rel="bookmark">(.*?)<\/a><\/h2>/';
        preg_match_all($pat1, $result, $m);
        
        preg_match_all($pat3, $result, $z);
       //print_r($m);print_r($z);die;


      
        foreach ($m[1] as $key => $v) {
            $v=str_replace("('",'', $v);
            $v=str_replace("')",'', $v);
            array_push($arr,$v);
        }
        $all_arr['thumb']=$arr;
        $all_arr['link']=$z[1];
        $all_arr['text']=$z[2];

        //array_push($all_arr,$arr,$z[1],$z[2]);
        $more=array();

        // $thumb_arr=array_chunk($all_arr['thumb'],2);
        // $link_arr=array_chunk($all_arr['link'],2);
        // $text_arr=array_chunk($all_arr['text'],2);
        
        for ($i=0; $i <count($all_arr['link']) ; $i++) { 
             array_push($more,$all_arr['thumb'][$i],$all_arr['link'][$i],$all_arr['text'][$i]);
        }
        $s=array_chunk($more,3);
        $res=array_chunk($s,2);
        
        return json(['res'=>$res]);
        // $this->assign('all',$all_arr);
        
        // return $this->fetch();
    	


    }


    public function detail()
    {
        header("Content-type: text/html; charset=utf-8");
        $link=Request::instance()->param('link');
        $arr=array();  //用来存储出现次数最多
        $all_arr=array();

        $str="";
        //$paged="1";
        $ch1 = curl_init();
        $url = $link;
         
        //$data1="paged={$paged}";
        curl_setopt($ch1, CURLOPT_URL,$url);
        // curl_setopt($ch1, CURLOPT_POST, 1); 
        // curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch1, CURLOPT_HEADER, 0); 
        curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
        $result=curl_exec($ch1); 
        curl_close($ch1);

        $pat1='/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?width=.+?>/i';
        
        
        preg_match_all($pat1, $result, $m);
        //print_r($m[1]);
        foreach ($m[1] as $k => $v) {
            if($v!=="http://wx1.sinaimg.cn/large/d030806aly1ftlwthq2uyj20ci0iqn5m.jpg")
            {
                $str.=strlen($v).',';
                $arr=explode(',',$str);
                
            }
            
           
        }

        $arr=array_count_values($arr); 
        arsort($arr); 
        $arr=array_keys($arr);
        foreach ($m[1] as $key => $value) {
            if($value!=="http://wx1.sinaimg.cn/large/d030806aly1ftlwthq2uyj20ci0iqn5m.jpg")
            {
                if(strlen($value)==$arr[0])
                {
                    array_push($all_arr,$value);
                }
            }
               
        }
        return json(['res'=>$all_arr]);die;
        print_r($all_arr);

    }
  

    public function mzt()
    {
        header("Content-type: text/html; charset=utf-8");
        $arr=array();
        $all_arr=array();
        $paged=Request::instance()->param('page');
        $ch1 = curl_init();
        $url = "http://www.jdlingyu.mobi/collection/meizitu";
         
        $data1="paged={$paged}";
        curl_setopt($ch1, CURLOPT_URL,$url);
        curl_setopt($ch1, CURLOPT_POST, 1); 
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch1, CURLOPT_HEADER, 0); 
        curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
        $result=curl_exec($ch1); 
        curl_close($ch1);



        $pat1='/<div style="background-image:url(.*?)" class="preview thumb-in"><\/div>/';
        
        $pat3='/<h2 class="entry-title"><a target="_blank" href="(.*?)" rel="bookmark">(.*?)<\/a><\/h2>/';
        preg_match_all($pat1, $result, $m);
        
        preg_match_all($pat3, $result, $z);
       // print_r($z);die;


      
        foreach ($m[1] as $key => $v) {
            $v=str_replace("('",'', $v);
            $v=str_replace("')",'', $v);
            array_push($arr,$v);
        }
        $all_arr['thumb']=$arr;
        $all_arr['link']=$z[1];
        $all_arr['text']=$z[2];

       
        $more=array();

        
        for ($i=0; $i <count($all_arr['link']) ; $i++) { 
             array_push($more,$all_arr['thumb'][$i],$all_arr['link'][$i],$all_arr['text'][$i]);
        }
        $s=array_chunk($more,3);
        $res=array_chunk($s,2);
        
        return json(['res'=>$res]);
      
        


    }

    public function ecy()
    {
        header("Content-type: text/html; charset=utf-8");
        $arr=array();
        $all_arr=array();
        $paged=Request::instance()->param('page');
        $ch1 = curl_init();
        $url = "http://www.jdlingyu.mobi/collection/zipai";
         
        $data1="paged={$paged}";
        curl_setopt($ch1, CURLOPT_URL,$url);
        curl_setopt($ch1, CURLOPT_POST, 1); 
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch1, CURLOPT_HEADER, 0); 
        curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
        $result=curl_exec($ch1); 
        curl_close($ch1);



        $pat1='/<div style="background-image:url(.*?)" class="preview thumb-in"><\/div>/';
        
        $pat3='/<h2 class="entry-title"><a target="_blank" href="(.*?)" rel="bookmark">(.*?)<\/a><\/h2>/';
        preg_match_all($pat1, $result, $m);
        
        preg_match_all($pat3, $result, $z);
       // print_r($z);die;


      
        foreach ($m[1] as $key => $v) {
            $v=str_replace("('",'', $v);
            $v=str_replace("')",'', $v);
            array_push($arr,$v);
        }
        $all_arr['thumb']=$arr;
        $all_arr['link']=$z[1];
        $all_arr['text']=$z[2];

       
        $more=array();

        
        for ($i=0; $i <count($all_arr['link']) ; $i++) { 
             array_push($more,$all_arr['thumb'][$i],$all_arr['link'][$i],$all_arr['text'][$i]);
        }
        $s=array_chunk($more,3);
        $res=array_chunk($s,2);
        
        return json(['res'=>$res]);
      
        


    }


    public function tdd()
    {
        header("Content-type: text/html; charset=utf-8");
        $arr=array();
        $all_arr=array();
        $paged=Request::instance()->param('page');
        $ch1 = curl_init();
        $url = "http://www.jdlingyu.mobi/collection/%e7%89%b9%e7%82%b9";
         
        $data1="paged={$paged}";
        curl_setopt($ch1, CURLOPT_URL,$url);
        curl_setopt($ch1, CURLOPT_POST, 1); 
        curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
        curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch1, CURLOPT_HEADER, 0); 
        curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
        $result=curl_exec($ch1); 
        curl_close($ch1);



        $pat1='/<div style="background-image:url(.*?)" class="preview thumb-in"><\/div>/';
        
        $pat3='/<h2 class="entry-title"><a target="_blank" href="(.*?)" rel="bookmark">(.*?)<\/a><\/h2>/';
        preg_match_all($pat1, $result, $m);
        
        preg_match_all($pat3, $result, $z);
       // print_r($z);die;


      
        foreach ($m[1] as $key => $v) {
            $v=str_replace("('",'', $v);
            $v=str_replace("')",'', $v);
            array_push($arr,$v);
        }
        $all_arr['thumb']=$arr;
        $all_arr['link']=$z[1];
        $all_arr['text']=$z[2];

       
        $more=array();

        
        for ($i=0; $i <count($all_arr['link']) ; $i++) { 
             array_push($more,$all_arr['thumb'][$i],$all_arr['link'][$i],$all_arr['text'][$i]);
        }
        $s=array_chunk($more,3);
        $res=array_chunk($s,2);
        
        return json(['res'=>$res]);
      
        


    }


   








}
